<template>
  <el-form ref="form" :rules="rules" :model="currentDepartCategory" label-width="100px" class="demo-form">
    <el-row :gutter="10">
      <el-col :span="24">
        <el-card class="box-card">
          <el-form-item label="分类" prop="name">
            <el-input v-model="currentDepartCategory.name"></el-input>
          </el-form-item>
          <el-form-item>
            <span style="float: right;">
                 <el-button type="primary" @click="save('form')">保存</el-button>
                   <el-button @click="back">返回</el-button>
            </span>
          </el-form-item>
        </el-card>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import { mapGetters } from "vuex";

export default {
  props: {
    isClose: Boolean
  },
  created() {},
  mounted() {},
  computed: {
    ...mapGetters({
      currentDepartCategory: "currentDepartCategory"
    })
  },
  data() {
    return {
      rules: {
        name: [{ required: true, message: "请输入分类名称", trigger: "blur" }]
      }
    };
  },
  methods: {
    save(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$store
            .dispatch("addDepartCategories", this.currentDepartCategory)
            .then(ret => {
              this.$notify({
                title: "添加成功",
                type: "success"
              });
              this.back();
            });
        } else {
          return false;
        }
      });
    },
    back() {
      this.$emit("close");
    }
  },
  components: {}
};
</script>
<style>
</style>
